define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/index' + location.search,
                    add_url: '',
                    edit_url: '',
                    del_url: '',
                    multi_url: 'user/multi',
                    import_url: '',
                    table: 'user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'group_id', title: __('Group_id')},
                        {field: 'username', title: __('Username'), operate: 'LIKE'},
                        // {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
                        // {field: 'password', title: __('Password'), operate: 'LIKE'},
                        // {field: 'salt', title: __('Salt'), operate: 'LIKE'},
                        // {field: 'email', title: __('Email'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'avatar', title: __('Avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'level', title: __('Level')},
                        {field: 'level', title: __('Level'), searchList: {"0":__("非会员"),"1":__('悦享游会员'),"2":__('尊享游会员'),"3":__('裕鹅会员'),}, formatter: Table.api.formatter.normal},

                        {field: 'gender', title: __('Gender'), searchList: {"1":__('Gender 1'),"0":__('Gender 0')}, formatter: Table.api.formatter.normal},
                        {field: 'idcard', title: __('Idcard'), operate: 'LIKE'},
                        {field: 'age', title: __('Age')},
                        {field: 'nation', title: __('Nation'), operate: 'LIKE'},
                        // {field: 'birthday', title: __('Birthday'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        // {field: 'bio', title: __('Bio'), operate: 'LIKE'},
                        // {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        // {field: 'score', title: __('Score')},
                        // {field: 'successions', title: __('Successions')},
                        // {field: 'maxsuccessions', title: __('Maxsuccessions')},
                        // {field: 'prevtime', title: __('Prevtime')},
                        // {field: 'logintime', title: __('Logintime')},
                        // {field: 'loginip', title: __('Loginip'), operate: 'LIKE'},
                        // {field: 'loginfailure', title: __('Loginfailure')},
                         {field: 'join_num', title: __('Join_num')},
                        // {field: 'joinip', title: __('Joinip'), operate: 'LIKE'},
                        // {field: 'jointime', title: __('Jointime')},
                        {field: 'createtime', title: __('Createtime')},
                        {field: 'updatetime', title: __('Updatetime')},
                        // {field: 'token', title: __('Token'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), operate: 'LIKE', formatter: Table.api.formatter.status},
                        // {field: 'verification', title: __('Verification'), operate: 'LIKE'},
                        // {field: 'belongto_office_id', title: __('Belongto_office_id')},
                        // {field: 'belongto_shop_id', title: __('Belongto_shop_id')},
                        // {field: 'belongto_store_id', title: __('Belongto_store_id')},
                        {field: 'branchofficeoffice.name', title: __('归属分公司'), operate: 'LIKE'},
                        {field: 'manystoreshop.name', title: __('归属门店'), operate: 'LIKE'},
                        {field: 'manystore.username', title: __('归属销售'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: '上会记录',
                                    text: __('上会记录'),
                                    classname: 'btn btn-info btn-dialog',
                                    icon: 'fa',
                                    url: 'goods_customer/index?user_id={ids}&user_join_num_add=1',
                                },
                                {
                                    name: '转为会员',
                                    text: __('转为会员'),
                                    classname: 'btn btn-warm btn-dialog',
                                    icon: 'fa',
                                    url: 'user/set_level',
                                },
                                {
                                    name: '跟踪记录',
                                    text: __('跟踪记录'),
                                    classname: 'btn btn-warm btn-dialog',
                                    icon: 'fa',
                                    url: 'user_follow/add?user_id={ids}',
                                },

                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        set_level: function () {
            Controller.api.bindevent();
        },

        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});